# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=box-js
pkgver=703.a3bb0c8
pkgrel=1
pkgdesc='A tool for studying JavaScript malware.'
groups=('blackarch' 'blackarch-malware')
arch=('any')
url='https://github.com/CapacitorSet/box-js'
license=('MIT')
depends=('nodejs' 'gnuplot')
makedepends=('git' 'npm')
source=("git+https://github.com/CapacitorSet/$pkgname.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  npm install --production

  find . -name package.json | xargs sed -i "s|$srcdir|/usr/share/box-js|"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname" README.md
  install -Dm 644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  rm README.md LICENSE

  cp -a * "$pkgdir/usr/share/$pkgname"

cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec node run.js "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

